#!/usr/bin/evn python
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   文件名称 :     __init__.py
   文件功能描述 :   功能描述
   创建人 :       小钟同学
   创建时间 :          2022/1/19
-------------------------------------------------
   修改描述-2022/1/19:
-------------------------------------------------
"""
import asyncio
from concurrent.futures import ThreadPoolExecutor


def run(coroutine_function, *args, **kwargs):
    if not asyncio.iscoroutinefunction(coroutine_function):
        raise TypeError('"coroutine_function" must be a coroutine_function.')
    try:
        coro = coroutine_function(*args, **kwargs)
        result = asyncio.run(coro)
        return result
    except:
        coro = coroutine_function(*args, **kwargs)
        with ThreadPoolExecutor() as executor:
            result = executor.submit(asyncio.run, coro).result()
            return result
